package pl.edu.pw.polygen.modeler.client.object.listener;

import pl.edu.pw.polygen.modeler.client.object.IPolygenObject;
import pl.edu.pw.polygen.modeler.client.workspace.IWorkspace;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseUpEvent;

public class SelectableControlListener extends BaseObjectListener {

	@Override
	public void onMouseDown(MouseDownEvent event, IPolygenObject polygenObject) {
		IWorkspace context = polygenObject.getContext();
		context.setMouseDownCatch(true);
		polygenObject.hold();
		context.addToHolded(polygenObject);
	}

	@Override
	public void onMouseUp(MouseUpEvent event, IPolygenObject polygenObject) {
		if (polygenObject.isHolded() == true) {
			polygenObject.drop();
			IWorkspace context = polygenObject.getContext();
			context.addToSelected(polygenObject);
		}
	}

	@Override
	public void onMouseOver(MouseOverEvent event, IPolygenObject polygenObject) {
		if (polygenObject.isSelected() == false && polygenObject.isHolded() == false) {
			polygenObject.over();
		}		
	}

	@Override
	public void onMouseOut(MouseOutEvent event, IPolygenObject polygenObject) {
		if (polygenObject.isSelected() == false && polygenObject.isHolded() == false) {
			polygenObject.out();
		}		
	}

}
